# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
import os


class Csdn4Pipeline(object):
    def process_item(self, item, spider):
        # print(item)
        name = item["cou_name"]
        teacher = item["tea_name"]
        stu_cnt = item["stu_cnt"]
        price = item["price"]
        times = item["times"]
        filename = "course/"+str(name)+".txt"
        fh = open(filename, "w")
        # print(filename)
        fh.write("课程名称: " + str(name)+"\n")
        fh.write("授课老师: " + str(teacher)+"\n")
        fh.write("学员数量: " + str(stu_cnt)+"\n")
        fh.write("课程价格: " + str(price)+"\n")
        fh.write("课程课时: " + str(times)+"\n")
        fh.close()
        # print('done')
        return item
